package cn.edu.scau.cmi.wuyihan.exercise11.Example11_7;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import javax.swing.JComboBox;
import javax.swing.JTextArea;

public class PoliceListen implements ItemListener {

	JComboBox choice;
	JTextArea textShow;
	public void setJComboBox(JComboBox box) {
		choice = box;
	}
	public void setJTextArea(JTextArea area) {
		textShow = area;
	}
	@Override
	public void itemStateChanged(ItemEvent arg0) {
		// TODO Auto-generated method stub
		textShow.setText(null);
		try {
			String fileName=choice.getSelectedItem().toString();
			File file=new File(fileName);
			FileReader inOne=new FileReader(file);
			BufferedReader inTwo=new BufferedReader(inOne);
			String string=null;
			while((string=inTwo.readLine())!=null) {
				textShow.append(string+"\n");
			}
			inOne.close();
			inTwo.close();
		}
		catch (Exception e) {
			// TODO: handle exception
			textShow.append(e.toString());
		}
	}

}
